<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 CMS 垃圾收集器：卡表与增量更新机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #667eea;
        }
        .section-divider {
            position: relative;
            text-align: center;
            margin: 3rem 0;
        }
        .section-divider::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: linear-gradient(to right, transparent, #e0e0e0, transparent);
        }
        .section-divider i {
            position: relative;
            background: white;
            padding: 0 1rem;
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            padding: 2px;
            border-radius: 0.5rem;
        }
        .highlight-box-inner {
            background: white;
            border-radius: 0.375rem;
            padding: 1.5rem;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                <i class="fas fa-memory mr-4"></i>深入理解 CMS 垃圾收集器
            </h1>
            <p class="text-2xl md:text-3xl mb-8 font-light">卡表与增量更新机制的奥秘</p>
            <div class="max-w-3xl mx-auto">
                <p class="text-lg leading-relaxed opacity-90">
                    在 Java 虚拟机的世界里，CMS（Concurrent Mark-Sweep）垃圾收集器通过精妙的卡表和增量更新机制，
                    实现了应用程序与垃圾回收的和谐共舞，让我们一起揭开这项技术的神秘面纱。
                </p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="max-w-4xl mx-auto mb-12">
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <i class="fas fa-info-circle text-4xl text-gradient mr-4"></i>
                    <h2 class="text-3xl font-bold">核心概念导览</h2>
                </div>
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    在 Java 的 CMS（Concurrent Mark-Sweep）垃圾收集器中，卡表（Card Table）和增量更新（Incremental Update）
                    是维护和优化垃圾回收过程的重要机制。这两项技术的巧妙结合，使得 CMS 能够在保证应用程序响应性的同时，
                    高效地完成垃圾回收任务。
                </p>
            </div>
        </div>

        <!-- Card Table Section -->
        <section class="mb-16">
            <div class="section-divider mb-8">
                <i class="fas fa-table text-2xl"></i>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-th text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold">卡表（Card Table）概述</h3>
                    </div>
                    <p class="text-gray-700 leading-relaxed mb-4">
                        <strong>卡表</strong>是一种用于跟踪对象的内存区域变化的结构，主要用于记录哪些内存区域的对象引用可能发生了变化。
                        在 CMS 垃圾收集器中，卡表用于支持增量更新的标记过程，提高了垃圾回收的效率。
                    </p>
                    <div class="mt-6 p-4 bg-purple-50 rounded-lg">
                        <p class="text-sm text-purple-800">
                            <i class="fas fa-lightbulb mr-2"></i>
                            卡表就像是内存的"变更日志"，记录着哪些区域发生了改变，让垃圾收集器能够精准定位需要重新检查的区域。
                        </p>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-tools text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold">卡表的维护机制</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold mb-1">初始化和结构</h4>
                                <p class="text-gray-600 text-sm">卡表是一个按页分块的结构，每个块（卡）代表一个内存页的部分区域。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold mb-1">卡表更新</h4>
                                <p class="text-gray-600 text-sm">当对象引用发生变化时，相应的卡会被标记为"脏"状态。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Write Barrier Highlight -->
            <div class="max-w-4xl mx-auto mb-12">
                <div class="highlight-box">
                    <div class="highlight-box-inner">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-shield-alt text-3xl text-gradient mr-4"></i>
                            <h3 class="text-2xl font-bold">写屏障（Write Barrier）</h3>
                        </div>
                        <p class="text-gray-700 leading-relaxed mb-4">
                            写屏障是一种机制，用于在对象的引用发生变化时更新卡表。CMS 收集器使用写屏障来维护卡表，
                            确保在并发标记期间能够及时捕捉到内存中的引用变化。
                        </p>
                        <div class="grid md:grid-cols-2 gap-4 mt-6">
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <i class="fas fa-sync-alt text-blue-500 mb-2"></i>
                                <p class="text-sm text-gray-700">实时监控引用变化</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <i class="fas fa-flag text-red-500 mb-2"></i>
                                <p class="text-sm text-gray-700">标记脏卡以待处理</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Incremental Update Section -->
        <section class="mb-16">
            <div class="section-divider mb-8">
                <i class="fas fa-sync text-2xl"></i>
            </div>

            <div class="bg-white rounded-2xl shadow-xl p-10 mb-12">
                <div class="flex items-center mb-6">
                    <i class="fas fa-chart-line text-4xl text-gradient mr-4"></i>
                    <h2 class="text-3xl font-bold">增量更新（Incremental Update）</h2>
                </div>
                <p class="text-lg leading-relaxed text-gray-700 mb-8">
                    <strong>增量更新</strong>是 CMS 垃圾收集器用来优化标记过程的一种技术。
                    它的主要目的是在并发标记阶段尽量减少对应用程序性能的影响。
                </p>

                <!-- Process Flow -->
                <div class="grid md:grid-cols-3 gap-6 mb-8">
                    <div class="text-center">
                        <div class="w-20 h-20 bg-gradient-to-br from-purple-500 to-pink-500 rounded-full flex items-center justify-center mx-auto mb-4 text-white text-2xl font-bold">
                            1
                        </div>
                        <h4 class="font-semibold mb-2">初始标记</h4>
                        <p class="text-sm text-gray-600">短暂停顿，标记根对象</p>
                    </div>
                    <div class="text-center">
                        <div class="w-20 h-20 bg-gradient-to-br from-blue-500 to-cyan-500 rounded-full flex items-center justify-center mx-auto mb-4 text-white text-2xl font-bold">
                            2
                        </div>
                        <h4 class="font-semibold mb-2">并发标记</h4>
                        <p class="text-sm text-gray-600">与应用程序并行执行</p>
                    </div>
                    <div class="text-center">
                        <div class="w-20 h-20 bg-gradient-to-br from-green-500 to-teal-500 rounded-full flex items-center justify-center mx-auto mb-4 text-white text-2xl font-bold">
                            3
                        </div>
                        <h4 class="font-semibold mb-2">最终标记</h4>
                        <p class="text-sm text-gray-600">处理脏卡，确保准确性</p>
                    </div>
                </div>

                <!-- Key Features -->
                <div class="bg-gray-50 rounded-xl p-6">
                    <h4 class="font-bold mb-4 flex items-center">
                        <i class="fas fa-key text-yellow-500 mr-2"></i>
                        关键特性
                    </h4>
                    <div class="grid md:grid-cols-2 gap-4">
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-3"></i>
                            <p class="text-sm text-gray-700">
                                <strong>并发标记：</strong>CMS 通过增量更新来处理那些在并发标记期间发生变化的对象引用。
                            </p>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-3"></i>
                            <p class="text-sm text-gray-700">
                                <strong>处理脏卡：</strong>最终标记阶段会检查所有"脏"状态的卡，确保垃圾回收的准确性。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Interactive Diagram -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-10">
                <h3 class="text-2xl font-bold mb-6 text-center">
                    <i class="fas fa-project-diagram mr-2 text-gradient"></i>
                    CMS 垃圾收集器工作流程
                </h3>
                <div class